package com.ympc.service.impl;

import com.ympc.mapper.AssignmentMapper;
import com.ympc.pojo.Assignment;
import com.ympc.service.AssignmentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AssignmentServiceImpl implements AssignmentService {
    
    @Resource
    private AssignmentMapper assignmentMapper;
    
    @Override
    public boolean publishAssignment(Assignment assignment) {
        assignment.setPublishTime(new Date());
        assignment.setStatus("published");
        return assignmentMapper.insertAssignment(assignment) > 0;
    }
    
    @Override
    public List<Assignment> getAssignmentsByTeacherId(Integer teacherId) {
        return assignmentMapper.findByTeacherId(teacherId);
    }
    
    @Override
    public List<Assignment> getAssignmentsByStatus(String status) {
        return assignmentMapper.findByStatus(status);
    }
    
    @Override
    public List<Assignment> getAssignmentsByTeacherIdAndStatus(Integer teacherId, String status) {
        return assignmentMapper.findByTeacherIdAndStatus(teacherId, status);
    }
    
    @Override
    public List<Assignment> getAssignmentsByClassId(Integer classId) {
        return assignmentMapper.findByClassId(classId);
    }
    
    @Override
    public Assignment getAssignmentById(Integer id) {
        return assignmentMapper.findById(id);
    }
    
    @Override
    public boolean updateAssignment(Assignment assignment) {
        return assignmentMapper.updateAssignment(assignment) > 0;
    }
    
    @Override
    public boolean updateAssignmentStatus(Integer id, String status) {
        return assignmentMapper.updateStatus(id, status) > 0;
    }
    
    @Override
    public boolean deleteAssignment(Integer id) {
        return assignmentMapper.deleteAssignment(id) > 0;
    }
}

